package com.ykdl.member.kid.adapters;

import java.util.ArrayList;

import com.lidroid.xutils.BitmapUtils;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.adapters.PraisesMeAdapters.ViewHolder;
import com.ykdl.member.kid.beans.PraiseBean;
import com.ykdl.member.kid.beans.TopicAndPostBean;
import com.ykdl.member.kid.beans.TopicAndPostListBean;
import com.ykdl.member.kid.circle.TopicAndResultActivity;
import com.ykdl.member.kid.image.ImageOptions;
import com.ykdl.member.kid.image.ImageOptionsFactory;
import com.ykdl.member.kid.person.PersonCenterActivity;
import com.ykdl.member.kid.util.DateUtil;
import com.ykdl.member.kid.widget.AsyncImageView;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MyReanswerListAdapter extends BaseAdapter{
	private Activity mContext ;
	private ArrayList<TopicAndPostBean>  list;
	private String TAG ;
	 private ImageOptions options=null ;
	 private BitmapUtils bitmapUtil ;
	public MyReanswerListAdapter(Activity context, String tag){
		this.mContext = context;
		bitmapUtil = new BitmapUtils(mContext);
		bitmapUtil.configDefaultLoadingImage(R.drawable.defualt_icon);
		bitmapUtil.configDefaultLoadFailedImage(R.drawable.defualt_icon);
	}
	public void setlist(ArrayList<TopicAndPostBean>  list) {
		this.list= list ;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (list != null) {
			return list.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		if (getCount() != 0) {
			return list.get(position-1);
		} else {
			return null;
		}
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null ;
		if (convertView==null) {
			convertView = RelativeLayout.inflate(mContext,
					R.layout.myreanswerlistadapter_item, null);
			holder = new ViewHolder();
			 holder.user_head =  (ImageView) convertView.findViewById(R.id.user_head);
			 holder.user_name=  (TextView) convertView.findViewById(R.id.user_name);
			 holder.user_grade=  (TextView) convertView.findViewById(R.id.grade);
			 holder.user_time=  (TextView) convertView.findViewById(R.id.user_time);
			 holder.user_age=  (TextView) convertView.findViewById(R.id.user_age);
			 holder.user_content=  (TextView) convertView.findViewById(R.id.user_content);
			 holder.user_address=  (TextView) convertView.findViewById(R.id.user_address);
			 holder.group_name=  (TextView) convertView.findViewById(R.id.group_name);
			 holder.reply_count=  (TextView) convertView.findViewById(R.id.reply_count);
			 holder.topic_reanser_name=  (TextView) convertView.findViewById(R.id.topic_reanser_name);
			 holder.topic_reanser_content=  (TextView) convertView.findViewById(R.id.topic_reanser_content);
			 convertView.setTag(holder);
		}else {
			holder = (ViewHolder)convertView.getTag();
		}
		 final  TopicAndPostBean bean= list.get(position) ;
		 if (list.get(position).getPost_actor().getAvatar_file_meta()!=null) {
				String url = list.get(position).getPost_actor().getAvatar_file_meta().getDownload_urls().getSmal().getUrl();
				bitmapUtil.display(holder.user_head, url);
				}else {
					holder.user_head.setImageResource(R.drawable.defualt_icon);
				}
		 holder.user_head.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(mContext, PersonCenterActivity.class);
					intent.putExtra(PersonCenterActivity.STR_ACTOR_ID, bean.getPost_actor().getActor_id());
					mContext.startActivity(intent);
				}
			});
		 holder.user_name.setText(list.get(position).getPost_actor_display_name());
		 holder.user_grade.setText(list.get(position).getPost_actor().getLevel()+"");
		 if (list.get(position).getExtra_data()!=null) {
			 if (list.get(position).getExtra_data().getBaby_days()!=null) {
				 holder.user_age.setText(DateUtil.getDayTip(list.get(position).getExtra_data().getBaby_days()));
			}
			 holder.topic_reanser_name.setText(list.get(position).getExtra_data().getParent_post_actor_name());
			 holder.topic_reanser_content.setText(list.get(position).getExtra_data().getParent_post_content());
		}
		 holder.user_time.setText(DateUtil.gettopicDate(list.get(position).getPost_time()));
		 holder.user_content.setText(list.get(position).getMessage());
		 if (list.get(position).getPost_actor().getProfile()!=null) {
			 holder.user_address.setText(list.get(position).getPost_actor().getProfile().getRegion());
		}
		 holder.group_name.setText(list.get(position).getGroup().getGroup_name());
		 
		return convertView;
	}
	class ViewHolder {
		 ImageView user_head ;
		 TextView  user_name,user_time,user_grade,
		 user_age,user_address,topic_reanser_name,
		 reply_count,group_name,topic_reanser_content,user_content;
	}


}
